﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace WindowsGame1
{
    public class BulletManager
    {
        public List<Lazor> lazors = new List<Lazor>();

        public List<Bullet> bullets = new List<Bullet>();

        public List<Bullet> freezeBullets = new List<Bullet>();

        public void Update(Timer t)
        {
            for (int i = 0; i < lazors.Count; )
            {
                if (lazors[i].Update(t) == false)
                    lazors.RemoveAt(i);
                else
                    i++;
            }

            for (int i = 0; i < bullets.Count; )
            {
                
                if (bullets[i].owner != null)
                    if (bullets[i].owner.IsAlive() == false)
                    {
                        float dec = t.Delta * 32;
                        bullets[i].size.X -= dec;
                        bullets[i].size.Y -= dec;
                    }

                if (bullets[i].Update(t) == false ||  bullets[i].size.X < 0 )
                {
                    bullets.RemoveAt(i);
                }
                else
                    i++;
            }
            
            for (int i = 0; i < freezeBullets.Count; )
            {
                if (freezeBullets[i].Update(t) == false)
                    freezeBullets.RemoveAt(i);
                else
                    i++;
            }
        }

        public void Draw(SpriteBatch sb)
        {
            foreach (Lazor l in lazors)
            {
                l.Draw(sb);
            }

            foreach (Bullet b in bullets)
            {
                b.Draw(sb);
            }

            foreach (Bullet b in freezeBullets)
            {
                b.Draw(sb);
            }
        }
    }
}
